/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package app.bus;

import app.dao.DatabaseInteraction;
import app.entities.Account;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Tuan Long
 */
public class AccountModel {

    public static Account checkLoginValid(String username, String password) {
        Account a = null;
        String query = "SELECT *FROM [User] WHERE [Username]='"+username+"' AND [Password]='"+password+"'";
        Connection cnn = DatabaseInteraction.getConnection();
        if (cnn != null) {
            ResultSet rs = DatabaseInteraction.getExcuteQuery(query);
            if (rs != null) {
                try {
                    while (rs.next()) {
                        a = new Account();
                        a.setUsername(rs.getString("Username"));
                        a.setPassword(rs.getString("Password"));
                        a.setFullname(rs.getString("Fullname"));
                        a.setUserrole(rs.getString("UserRole"));
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(AccountModel.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        return a;
    }
}
